<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Frequently Asked Questions</title>
<link rel="stylesheet" href="../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Boost.Test">
<link rel="up" href="../index.html" title="Boost.Test">
<link rel="prev" href="practical_usage_recommendations/web_wisdom.html" title="Web Wisdom">
<link rel="next" href="section_glossary.html" title="Glossary">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
<td align="center"><a href="../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="practical_usage_recommendations/web_wisdom.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="section_glossary.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="boost_test.section_faq"></a><a class="link" href="section_faq.html" title="Frequently Asked Questions">Frequently Asked Questions</a>
</h2></div></div></div>
<h4>
<a name="boost_test.section_faq.h0"></a>
      <span class="phrase"><a name="boost_test.section_faq.where_the_latest_version_of_the_"></a></span><a class="link" href="section_faq.html#boost_test.section_faq.where_the_latest_version_of_the_">Where the
      latest version of the Boost Test Library is located?</a>
    </h4>
<p>
      The latest version of Boost Test Library is available online at <a href="http://www.boost.org/libs/test" target="_top">http://www.boost.org/libs/test</a>.
    </p>
<h4>
<a name="boost_test.section_faq.h1"></a>
      <span class="phrase"><a name="boost_test.section_faq.bug_report_of_feature_request_wh"></a></span><a class="link" href="section_faq.html#boost_test.section_faq.bug_report_of_feature_request_wh">Bug report
      of feature request: what should I do?</a>
    </h4>
<p>
      You can send a bug report or a feature request to the boost users' mailing
      list boost-users@lists.boost.org and/or fill a ticket on the GitHub issues
      of the project <a href="https://github.com/boostorg/test" target="_top">https://github.com/boostorg/test</a>.
    </p>
<h4>
<a name="boost_test.section_faq.h2"></a>
      <span class="phrase"><a name="boost_test.section_faq.how_to_create_test_case_using_th"></a></span><a class="link" href="section_faq.html#boost_test.section_faq.how_to_create_test_case_using_th">How to create
      test case using the Unit Test Framework?</a>
    </h4>
<p>
      To create a test case, use the macro
    </p>
<pre class="programlisting"><a class="link" href="utf_reference/test_org_reference/test_org_boost_auto_test_case.html" title="BOOST_AUTO_TEST_CASE"><code class="computeroutput"><span class="identifier">BOOST_AUTO_TEST_CASE</span></code></a><span class="special">(</span> <span class="identifier">test_function</span> <span class="special">);</span>
</pre>
<p>
      For more details see the Unit Test Framework <a class="link" href="utf_reference/test_org_reference/test_org_boost_auto_test_case.html" title="BOOST_AUTO_TEST_CASE"><code class="computeroutput"><span class="identifier">BOOST_AUTO_TEST_CASE</span></code></a> documentation.
    </p>
<h4>
<a name="boost_test.section_faq.h3"></a>
      <span class="phrase"><a name="boost_test.section_faq.is_boost_test_thread_safe"></a></span><a class="link" href="section_faq.html#boost_test.section_faq.is_boost_test_thread_safe">Is
      Boost.Test thread safe?</a>
    </h4>
<p>
      Short answer: no, but we welcome patches!
    </p>
<p>
      Longer answer: Boost.Test currently has no synchronization mechanisms in place
      to avoid any race when multiple threads are calling the assertion macros. For
      instance this code
    </p>
<pre class="programlisting"><span class="identifier">BOOST_TEST_CASE</span><span class="special">(</span><span class="identifier">test_parallel</span><span class="special">)</span>
<span class="special">{</span>
    <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">&gt;</span> <span class="identifier">vect</span><span class="special">(</span><span class="number">10</span><span class="special">);</span>
    <span class="identifier">std</span><span class="special">::</span><span class="identifier">for_each</span><span class="special">(</span>
        <span class="identifier">std</span><span class="special">::</span><span class="identifier">execution</span><span class="special">::</span><span class="identifier">par_unseq</span><span class="special">,</span>
        <span class="identifier">vect</span><span class="special">.</span><span class="identifier">begin</span><span class="special">(),</span>
        <span class="identifier">vect</span><span class="special">.</span><span class="identifier">end</span><span class="special">(),</span>
        <span class="special">[](</span><span class="keyword">auto</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">str</span><span class="special">)</span>
        <span class="special">{</span>
            <span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="identifier">str</span> <span class="special">==</span> <span class="string">""</span><span class="special">);</span>
        <span class="special">});</span>
<span class="special">}</span>
</pre>
<p>
      will not work as expected as the assertion <code class="computeroutput"><span class="identifier">BOOST_TEST</span></code>
      will be called from multiple threads.
    </p>
<h4>
<a name="boost_test.section_faq.h4"></a>
      <span class="phrase"><a name="boost_test.section_faq.how_to_create_test_suite_using_t"></a></span><a class="link" href="section_faq.html#boost_test.section_faq.how_to_create_test_suite_using_t">How to create
      test suite using the Unit Test Framework?</a>
    </h4>
<p>
      To create a test suite use the macro
    </p>
<pre class="programlisting"><a class="link" href="utf_reference/test_org_reference/test_org_boost_auto_test_suite.html" title="BOOST_AUTO_TEST_SUITE"><code class="computeroutput"><span class="identifier">BOOST_AUTO_TEST_SUITE</span></code></a><span class="special">(</span> <span class="identifier">suite_name</span> <span class="special">);</span>
</pre>
<p>
      For more details see the Unit Test Framework <a class="link" href="utf_reference/test_org_reference/test_org_boost_auto_test_suite.html" title="BOOST_AUTO_TEST_SUITE"><code class="computeroutput"><span class="identifier">BOOST_AUTO_TEST_SUITE</span></code></a> documentation.
    </p>
<h4>
<a name="boost_test.section_faq.h5"></a>
      <span class="phrase"><a name="boost_test.section_faq.why_did_i_get_a_linker_error_whe"></a></span><a class="link" href="section_faq.html#boost_test.section_faq.why_did_i_get_a_linker_error_whe">Why did I
      get a linker error when compiling my test program?</a>
    </h4>
<p>
      Boost Test Library components provide several usage variants: to create a test
      program you can link with the one of the precompiled library variants or use
      header-only variant. For example, to use Unit Test Framework you may either
      include
    </p>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">test</span><span class="special">/</span><span class="identifier">unit_test</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
</pre>
<p>
      and link with
    </p>
<pre class="programlisting"><span class="identifier">libunit_test_framework</span><span class="special">.</span><span class="identifier">lib</span></pre>
<p>
      or you can include
    </p>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">test</span><span class="special">/</span><span class="identifier">included</span><span class="special">/</span><span class="identifier">unit_test</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
</pre>
<p>
      in which case you should not need to link with any pre-compiled component.
      Note also that you should strictly follow specification on initialization function
      in other case some compilers may produce linker error like this.
    </p>
<pre class="programlisting"><span class="identifier">Unresolved</span> <span class="identifier">external</span> <span class="identifier">init_unit_test_suite</span><span class="special">(</span><span class="keyword">int</span><span class="special">,</span> <span class="keyword">char</span><span class="special">**).</span>
</pre>
<p>
      The reason for this error is that in your implementation you should specify
      second argument of <code class="computeroutput"><span class="identifier">init_unit_test_suite</span></code>
      exactly as in the specification, i.e.: <code class="computeroutput"><span class="keyword">char</span><span class="special">*</span> <span class="special">[]</span></code>.
    </p>
<h4>
<a name="boost_test.section_faq.h6"></a>
      <span class="phrase"><a name="boost_test.section_faq.how_can_i_redirect_testing_outpu"></a></span><a class="link" href="section_faq.html#boost_test.section_faq.how_can_i_redirect_testing_outpu">How can I
      redirect testing output?</a>
    </h4>
<p>
      Use
    </p>
<pre class="programlisting"><span class="identifier">unit_test_log</span><span class="special">::</span><span class="identifier">instance</span><span class="special">().</span><span class="identifier">set_log_output</span><span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">ostream</span> <span class="special">&amp;</span> <span class="special">)</span></pre>
<p>
      For more details see the <span class="emphasis"><em>Unit Test Framework</em></span> <a class="link" href="testing_tools/output_stream_testing.html" title="Output streams testing tool">output
      test stream</a> documentation.
    </p>
<h4>
<a name="boost_test.section_faq.h7"></a>
      <span class="phrase"><a name="boost_test.section_faq.i_want_different_default_log_tra"></a></span><a class="link" href="section_faq.html#boost_test.section_faq.i_want_different_default_log_tra">I want different
      default log trace level</a>
    </h4>
<p>
      Use environment variable <a class="link" href="utf_reference/rt_param_reference/log_level.html" title="log_level"><code class="computeroutput"><span class="identifier">BOOST_TEST_LOG_LEVEL</span></code></a> to define desired
      log trace level. You still will be able to reset this value from the command
      line. For the list of acceptable values see the <span class="emphasis"><em>Unit Test Framework</em></span>
      <a class="link" href="runtime_config.html" title="Runtime parameters">runtime configuration</a> documentation.
    </p>
<h4>
<a name="boost_test.section_faq.h8"></a>
      <span class="phrase"><a name="boost_test.section_faq.is_there_dll_version_of_boost_te"></a></span><a class="link" href="section_faq.html#boost_test.section_faq.is_there_dll_version_of_boost_te">Is there
      DLL version of Boost.Test components available on Win32 platform?</a>
    </h4>
<p>
      Yes. Starting with Boost 1.34.0.
    </p>
<h4>
<a name="boost_test.section_faq.h9"></a>
      <span class="phrase"><a name="boost_test.section_faq.how_to_set_up_a_cmake_project_us"></a></span><a class="link" href="section_faq.html#boost_test.section_faq.how_to_set_up_a_cmake_project_us">How to set
      up a CMake project using <span class="emphasis"><em>Unit Test Framework</em></span> (extended)</a>
    </h4>
<p>
      Suppose, you are building a test module from one translation unit <code class="computeroutput"><span class="identifier">test_file</span><span class="special">.</span><span class="identifier">cpp</span></code>. First, let's do it using the <a class="link" href="usage_variants.html#boost_test.usage_variants.single_header">header-only
      usage variant</a> of the <span class="emphasis"><em>Unit Test Framework</em></span>.
    </p>
<p>
      Let's paste the following content in a <code class="computeroutput"><span class="identifier">CMakeLists</span><span class="special">.</span><span class="identifier">txt</span></code> at the
      same location than our test file <code class="computeroutput"><span class="identifier">test_file</span><span class="special">.</span><span class="identifier">cpp</span></code>:
    </p>
<pre class="programlisting">cmake_minimum_required(VERSION 2.8.7)
project(my_first_test)
enable_testing()

# indicates the location of the boost installation tree.
# hard-coded for our simple example.
set(BOOST_INCLUDE_DIRS $boost_installation_prefix/include)

# creates the executable
add_executable(test_executable test_file.cpp)
# indicates the include paths
target_include_directories(test_executable PRIVATE ${BOOST_INCLUDE_DIRS})

# declares a test with our executable
add_test(NAME test1 COMMAND test_executable)
</pre>
<p>
      We will now create the build directory for this project (separate directory),
      configure and build the project, as follow:
    </p>
<pre class="programlisting"><span class="special">&gt;</span> <span class="identifier">cd</span> $<span class="identifier">test_path</span>
<span class="special">&gt;</span> <span class="identifier">mkdir</span> <span class="identifier">build</span>     <a class="co" name="boost_test.section_faq.c0" href="section_faq.html#boost_test.section_faq.c1"><img src="../../../../../doc/src/images/callouts/1.png" alt="1" border="0"></a>
<span class="special">&gt;</span> <span class="identifier">cd</span> <span class="identifier">build</span>
<span class="special">&gt;</span> <span class="identifier">cmake</span>  <span class="special">..</span>       <a class="co" name="boost_test.section_faq.c2" href="section_faq.html#boost_test.section_faq.c3"><img src="../../../../../doc/src/images/callouts/2.png" alt="2" border="0"></a>
<span class="special">&gt;</span> <span class="identifier">cmake</span> <span class="special">--</span><span class="identifier">build</span> <span class="special">.</span> <a class="co" name="boost_test.section_faq.c4" href="section_faq.html#boost_test.section_faq.c5"><img src="../../../../../doc/src/images/callouts/3.png" alt="3" border="0"></a>
<span class="special">&gt;</span> <span class="identifier">ctest</span>           <a class="co" name="boost_test.section_faq.c6" href="section_faq.html#boost_test.section_faq.c7"><img src="../../../../../doc/src/images/callouts/4.png" alt="4" border="0"></a>
</pre>
<div class="calloutlist"><table border="0" summary="Callout list">
<tr>
<td width="5%" valign="top" align="left"><p><a name="boost_test.section_faq.c1"></a><a href="#boost_test.section_faq.c0"><img src="../../../../../doc/src/images/callouts/1.png" alt="1" border="0"></a> </p></td>
<td valign="top" align="left"><p>
          we create a directory dedicated to the build, to avoid any pollution of
          the sources with the temporary build files
        </p></td>
</tr>
<tr>
<td width="5%" valign="top" align="left"><p><a name="boost_test.section_faq.c3"></a><a href="#boost_test.section_faq.c2"><img src="../../../../../doc/src/images/callouts/2.png" alt="2" border="0"></a> </p></td>
<td valign="top" align="left"><p>
          configuration of the project
        </p></td>
</tr>
<tr>
<td width="5%" valign="top" align="left"><p><a name="boost_test.section_faq.c5"></a><a href="#boost_test.section_faq.c4"><img src="../../../../../doc/src/images/callouts/3.png" alt="3" border="0"></a> </p></td>
<td valign="top" align="left"><p>
          this command builds the project, cmake drives a native tool that is configured
          on the previous command line
        </p></td>
</tr>
<tr>
<td width="5%" valign="top" align="left"><p><a name="boost_test.section_faq.c7"></a><a href="#boost_test.section_faq.c6"><img src="../../../../../doc/src/images/callouts/4.png" alt="4" border="0"></a> </p></td>
<td valign="top" align="left"><p>
          runs the tests declared in the project and prints a report
        </p></td>
</tr>
</table></div>
<p>
      In the case you are using the <a class="link" href="usage_variants.html#boost_test.usage_variants.shared_lib">shared
      libraries</a> variant of <span class="emphasis"><em>Unit Test Framework</em></span>, some
      modifications should be done in your CMakeLists.txt.
    </p>
<pre class="programlisting">cmake_minimum_required(VERSION 2.8.11)
project(my_first_test)
enable_testing()

# replace XX with the version you have
set(Boost_ADDITIONAL_VERSIONS "1.XX" "1.XX.0")

# finds boost, triggers an error otherwise
find_package(Boost XX REQUIRED COMPONENTS unit_test_framework)

# creates the executable
add_executable(test_executable test_file.cpp)
# indicates the include paths
target_include_directories(test_executable PRIVATE ${Boost_INCLUDE_DIRS})
# indicates the shared library variant
target_compile_definitions(test_executable PRIVATE "BOOST_TEST_DYN_LINK=1")
# indicates the link paths
target_link_libraries(test_executable ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})

# declares a test with our executable
add_test(NAME test1 COMMAND test_executable)

</pre>
<p>
      We will now create the build directory for this project (separate directory),
      configure and build the project, as follow:
    </p>
<pre class="programlisting"><span class="special">&gt;</span> <span class="identifier">cd</span> $<span class="identifier">test_path</span>
<span class="special">&gt;</span> <span class="identifier">mkdir</span> <span class="identifier">build</span> <a class="co" name="boost_test.section_faq.c8" href="section_faq.html#boost_test.section_faq.c9"><img src="../../../../../doc/src/images/callouts/1.png" alt="1" border="0"></a>
<span class="special">&gt;</span> <span class="identifier">cd</span> <span class="identifier">build</span>
<span class="special">&gt;</span> <span class="identifier">cmake</span> <span class="special">-</span><span class="identifier">DBOOST_ROOT</span><span class="special">=</span>$<span class="identifier">boost_installation_prefix</span> <span class="special">..</span> <a class="co" name="boost_test.section_faq.c10" href="section_faq.html#boost_test.section_faq.c11"><img src="../../../../../doc/src/images/callouts/2.png" alt="2" border="0"></a>
<span class="special">&gt;</span> <span class="identifier">cmake</span> <span class="special">--</span><span class="identifier">build</span> <span class="special">.</span> <a class="co" name="boost_test.section_faq.c12" href="section_faq.html#boost_test.section_faq.c13"><img src="../../../../../doc/src/images/callouts/3.png" alt="3" border="0"></a>
<span class="special">&gt;</span> <span class="identifier">ctest</span>           <a class="co" name="boost_test.section_faq.c14" href="section_faq.html#boost_test.section_faq.c15"><img src="../../../../../doc/src/images/callouts/4.png" alt="4" border="0"></a>
</pre>
<div class="calloutlist"><table border="0" summary="Callout list">
<tr>
<td width="5%" valign="top" align="left"><p><a name="boost_test.section_faq.c9"></a><a href="#boost_test.section_faq.c8"><img src="../../../../../doc/src/images/callouts/1.png" alt="1" border="0"></a> </p></td>
<td valign="top" align="left"><p>
          we create a directory dedicated to the build, to avoid any pollution of
          the sources with the temporary build files
        </p></td>
</tr>
<tr>
<td width="5%" valign="top" align="left"><p><a name="boost_test.section_faq.c11"></a><a href="#boost_test.section_faq.c10"><img src="../../../../../doc/src/images/callouts/2.png" alt="2" border="0"></a> </p></td>
<td valign="top" align="left"><p>
          configuration of the project, the <code class="computeroutput"><span class="identifier">BOOST_ROOT</span></code>
          configuration element indicates the Boost module of <code class="computeroutput"><span class="identifier">cmake</span></code>
          where to find our installation
        </p></td>
</tr>
<tr>
<td width="5%" valign="top" align="left"><p><a name="boost_test.section_faq.c13"></a><a href="#boost_test.section_faq.c12"><img src="../../../../../doc/src/images/callouts/3.png" alt="3" border="0"></a> </p></td>
<td valign="top" align="left"><p>
          this command builds the project, cmake drives a native tool that is configured
          on the previous command line
        </p></td>
</tr>
<tr>
<td width="5%" valign="top" align="left"><p><a name="boost_test.section_faq.c15"></a><a href="#boost_test.section_faq.c14"><img src="../../../../../doc/src/images/callouts/4.png" alt="4" border="0"></a> </p></td>
<td valign="top" align="left"><p>
          runs the tests declared in the project and prints a report
        </p></td>
</tr>
</table></div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2001-2022 Boost.Test contributors<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="practical_usage_recommendations/web_wisdom.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="section_glossary.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
